import {defHttp} from '/@/utils/http/axios';
import { useMessage } from "/@/hooks/web/useMessage";

const { createConfirm } = useMessage();

enum Api {
  list = '/ps/psPreProductionArrangementPlans/list',
  getList = '/ps/psPreProductionArrangementPlans/getList',
  queryPageList = '/ps/psPreProductionArrangementPlans/list',
  save='/ps/psPreProductionArrangementPlans/add',
  edit='/ps/psPreProductionArrangementPlans/edit',
  deleteOne = '/ps/psPreProductionArrangementPlans/delete',
  deleteBatch = '/ps/psPreProductionArrangementPlans/deleteBatch',
  importExcel = '/ps/psPrePlanningScheduling/importExcel',
  exportXls = '/ps/psPreProductionArrangementPlans/exportXls',
  psProductionArrangementPlansItemList = '/ps/psProductionArrangementPlans/queryPsProductionArrangementPlansItemByMainId',
  release = '/ps/psPreProductionArrangementPlans/release',
  releaseMRP = '/ps/psPreProductionArrangementPlans/releaseMRP',
  distribute = '/ps/psPreProductionArrangementPlans/distribute',
  unDistribute = '/ps/psPreProductionArrangementPlans/unDistribute',
  psProductionArrangementPlansDistribute = '/ps/psPreProductionArrangementPlansDistribute/list',
  detailItem = '/ps/psPreProductionArrangementPlansDayDetalis/list',
  delDetailItem =  '/ps/psPreProductionArrangementPlansDayDetalis/delete',
  changeProductionArrangementPlansDayDetalis = "/ps/psPreProductionArrangementPlansDayDetalis/change"
}
/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;

/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;
/**
 * 查询子表数据
 * @param params
 */
export const psProductionArrangementPlansItemList = Api.psProductionArrangementPlansItemList;
/**
 * 列表接口
 * @param params
 */
export const list = (params) =>
  defHttp.get({url: Api.list, params});
// 排产计划 主排产内容列表
export const getList = (params) =>
  defHttp.post({url: Api.getList, params},{ joinParamsToUrl: true });


export const queryPageList = (params) => defHttp.get({url: Api.list, params});


export const deleteOne = (params,handleSuccess) => {
  return defHttp.delete({url: Api.deleteOne, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}
// 释放订单
export const releaseMRP = (params) => {
   return defHttp.post({url:Api.releaseMRP,params},{joinParamsToUrl : true})
}
// 释放订单
export const releaseOrder = (params) => {
   return defHttp.post({url:Api.release,params},{joinParamsToUrl : true})
}
// 下发计划
export const distributePlan = (params) => {
  return defHttp.post({url:Api.distribute,params},{joinParamsToUrl : true})
}
// 取消下发
export const unDistributePlan = (params) => {
  return defHttp.post({url:Api.unDistribute,params},{joinParamsToUrl : true})
}
/**
 * 查询子表数据
 * @param params
 */
export const psProductionArrangementPlansDistribute = (params) => defHttp.get({ url: Api.psProductionArrangementPlansDistribute, params });
// 排产计划当天详情-分页列表查询
export const getDetailItem = (params) =>
  defHttp.get({ url: Api.detailItem, params });
// 排产计划当天详情-通过id删除
export const deleteDetailItem = (params) => {
  return defHttp.delete({ url: Api.delDetailItem, params }, { joinParamsToUrl: true });
}
// 排产计划当天详情- 修改生产线
export const postChangeProductionArrangementPlansDayDetalis = (params) => {
  return defHttp.post({ url: Api.changeProductionArrangementPlansDayDetalis, params }, { joinParamsToUrl: true })
}
/**
 * 批量删除
 * @param params
 */
export const batchDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: Api.deleteBatch, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}
/**
 * 保存或者更新
 * @param params
 */
export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({url: url, params});
}
